package com.share.lottery.adapter;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONException;
import org.json.JSONObject;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.BaseExpandableListAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lidroid.xutils.BitmapUtils;
import com.share.lottery.R;
import com.share.lottery.model.CaiboRmdBean;
import com.share.lottery.model.StaticsBean;
import com.share.lottery.model.Statisc;
import com.share.lottery.utils.JsonUtil;
import com.share.lottery.utils.StringUtil;

/**
 * @author py
 *统计
 */
public class ZjCommendStatisticsAdapter extends BaseAdapter {
	private BitmapUtils bitmapUtils;
	private List<StaticsBean> userList = new ArrayList<StaticsBean>();
	private  Context context;
	public ZjCommendStatisticsAdapter(Context context) {
		this.context = context;
		if (bitmapUtils == null) {
			bitmapUtils = new BitmapUtils(context);
		}
	}
	public int getCount() {

		return userList.size();
	}


	public StaticsBean getItem(int arg0) {

		return userList.get(arg0);
	}


	public long getItemId(int arg0) {

		return arg0;
	}


	public View getView(int position, View convertView, ViewGroup arg2) {
		StaticsBean staticsBean = userList.get(position);
		ViewHolder viewHolder = null;
		if (convertView == null) {
			convertView = LayoutInflater.from(context).inflate(
					R.layout.item_static, null);
			viewHolder = new ViewHolder();

			viewHolder.tvCz = (TextView) convertView.findViewById(R.id.tv_cz);// 彩种
			viewHolder.tvZs = (TextView) convertView.findViewById(R.id.tv_zs);//总数
			viewHolder.tvCg = (TextView) convertView.findViewById(R.id.tv_cgs);
			viewHolder.tvCgl = (TextView) convertView.findViewById(R.id.tv_cgl);

			viewHolder.tvName = (TextView) convertView.findViewById(R.id.tv_name);
			viewHolder.tvName1 = (TextView) convertView.findViewById(R.id.tv_name1);
			viewHolder.tvName2 = (TextView) convertView.findViewById(R.id.tv_name2);
			viewHolder.linearLayout = (LinearLayout) convertView.findViewById(R.id.line_one);
			viewHolder.linearLayout1 = (LinearLayout) convertView.findViewById(R.id.line_two);
			viewHolder.linearLayout2 = (LinearLayout) convertView.findViewById(R.id.line_three);
			viewHolder.tvbl = (TextView) convertView.findViewById(R.id.tv_ratio);
			viewHolder.tvbl1 = (TextView) convertView.findViewById(R.id.tv_ratio1);
			viewHolder.tvbl2 = (TextView) convertView.findViewById(R.id.tv_ratio2);
			
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}
		viewHolder.tvCz.setText(staticsBean.getName());
		viewHolder.tvZs.setText("总数:"+staticsBean.getTotal()+"个");
		viewHolder.tvCg.setText("成功:"+staticsBean.getSuccess()+"个");
		//		int sucess = staticsBean.getSuccess();
		//		int total = staticsBean.getTotal();
		viewHolder.tvCgl.setText("成功率"+(staticsBean.getRatio()));
		String lotteries = staticsBean.getLotteries();
		if (!StringUtil.isNullOrEmpty(lotteries)) {
			List<Statisc> statiscs = JsonUtil.parseArray(lotteries,Statisc.class);
			for (int i = 0; i < statiscs.size(); i++) {
				if (i == 0) {
					viewHolder.linearLayout.setVisibility(View.VISIBLE);
					viewHolder.linearLayout1.setVisibility(View.GONE);
					viewHolder.linearLayout2.setVisibility(View.GONE);
					viewHolder.tvName.setText(staticsBean.getName());
					viewHolder.tvbl.setText(staticsBean.getRatio());
				}
				else if (i == 1) {
					viewHolder.linearLayout.setVisibility(View.VISIBLE);
					viewHolder.linearLayout1.setVisibility(View.VISIBLE);
					viewHolder.linearLayout2.setVisibility(View.GONE);
					viewHolder.tvName.setText(staticsBean.getName());
					viewHolder.tvbl.setText(staticsBean.getRatio());
					viewHolder.tvName1.setText(staticsBean.getName());
					viewHolder.tvbl1.setText(staticsBean.getRatio());
				}
				else if (i == 2) {
					viewHolder.linearLayout.setVisibility(View.VISIBLE);
					viewHolder.linearLayout1.setVisibility(View.VISIBLE);
					viewHolder.linearLayout2.setVisibility(View.VISIBLE);
					viewHolder.tvName.setText(staticsBean.getName());
					viewHolder.tvbl.setText(staticsBean.getRatio());
					viewHolder.tvName1.setText(staticsBean.getName());
					viewHolder.tvbl1.setText(staticsBean.getRatio());
					viewHolder.tvName2.setText(staticsBean.getName());
					viewHolder.tvbl2.setText(staticsBean.getRatio());
				}

			}
			//			viewHolder.tvName.setText(statisc.getName());
			//			viewHolder.tvbl.setText("成功率"+statisc.getRatio()+"%");

		}

		return convertView;
	}
	class ViewHolder {
		TextView tvCz;//彩种

		TextView tvCg;//成功数
		TextView tvCgl;//成功率
		TextView tvZs;//请关注

		TextView tvName;//名字
		TextView tvbl;//比率

		TextView tvName1;//名字
		TextView tvbl1;//比率

		TextView tvName2;//名字
		TextView tvbl2;//比率

		LinearLayout linearLayout;
		LinearLayout linearLayout1;
		LinearLayout linearLayout2;




	}

	/**
	 * 添加数据
	 * 
	 * @param rows
	 */
	public void addDatas(List<StaticsBean> rows) {

		userList.addAll(rows);

		notifyDataSetChanged();
	}

	/**
	 * 清空数据
	 */
	public void clearDatas() {

		userList.clear();
		notifyDataSetChanged();
	}



}
